<template>
  <div class="toast" v-show="isShow">{{ message }}</div>
</template>

<script>
  export default {
    name: 'toast',
    data() {
      return {
        message: '',
        isShow: false
      }
    },
    methods: {
      show(message, duration = 1500) {
        this.message = message
        this.isShow = true
        setTimeout(() => {
          ;(this.isShow = false), (this.message = '')
        }, duration)
      }
    }
  }
</script>

<style lang="less" scoped>
  .toast {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 999;
    padding: 5px 10px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 5px;
    color: #fff;
  }
</style>
